﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：ManualEntryInfo
// 文件功能描述：手工录入业务逻辑层
//
// 
// 创建标识：2012-03-27 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class ManualEntryInfo
    {
        /// <summary>
        /// ID主键
        /// </summary>
        public int ID
        {
            get;
            set;
        }
        /// <summary>
        /// 日期(精确到日)
        /// </summary>
        public DateTime RDATE
        {
            get;
            set;
        }
        /// <summary>
        /// 食堂名称
        /// </summary>
        public string NODENAME
        {
            get;
            set;
        }
        /// <summary>
        /// 餐次
        /// </summary>
        public string PERIOD_NAME
        {
            get;
            set;
        }
        /// <summary>
        /// 名称
        /// </summary>
        public string DEPOSITNAME
        {
            get;
            set;
        }
        /// <summary>
        /// 单价
        /// </summary>
        public decimal Price
        {
            get;
            set;
        }
        /// <summary>
        /// 数量
        /// </summary>
        public int Count
        {
            get;
            set;
        }
        /// <summary>
        /// 金额
        /// </summary>
        public decimal ConMoney
        {
            get;
            set;
        }
        /// <summary>
        /// 操作人
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }
        /// <summary>
        /// 食堂
        /// </summary>
        public int MacID
        {
            get;
            set;
        }
        /// <summary>
        /// 餐次
        /// </summary>
        public int PeriodCode
        {
            get;
            set;
        }
        /// <summary>
        /// 名称
        /// </summary>
        public int DepositTypeID
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单编号
        /// </summary>
        public int MenuId
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单名称
        /// </summary>
        public string MenuName
        {
            get;
            set;
        }
        /// <summary>
        /// 菜单编号的集合
        /// </summary>
        public string MenuAll
        {
            get;
            set;
        }

        private DataAccessManualEntry dar;
        private int ManualEntrycount;
        public int _ManualEntrycount
        {
            get { return ManualEntrycount; }
        }
        public ManualEntryInfo(bool isgetcount)
        {
            dar = new DataAccessManualEntry();
            if (isgetcount)
            {
                ManualEntrycount = GetManualEntryCount();
            }
        }
        public ManualEntryInfo()
        { }

        public IList<ManualEntryInfo> SelLeftBox(string strquery)
        {
            IList<ManualEntryInfo> menlist = new List<ManualEntryInfo>();
            ManualEntryInfo meninfo;
            DataSet ds = dar.SelLeftBox(strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                meninfo = new ManualEntryInfo()
                {
                    MenuId = Convert.ToInt32(item["MenuId"]),
                    MenuName = item["MenuName"].ToString()
                };
                menlist.Add(meninfo);
            }
            return menlist;
        }

        /// <summary>
        /// 获取所有手工录入的数量
        /// </summary>
        /// <returns></returns>
        private int GetManualEntryCount()
        {
            return dar.GetManualEntryCount();
        }

        /// <summary>
        /// 获取所有手工录入的数量
        /// </summary>
        /// <returns></returns>
        public int GetManualEntryCount(string where)
        {
            return dar.GetManualEntryCount(where);
        }

        /// <summary>
        /// 获取食堂名称列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetMacID()
        {
            return dar.GetMacID();
        }

        /// <summary>
        /// 获取餐次(用于绑定下拉框)
        /// </summary>
        /// <returns></returns>
        public DataSet GetPeriodCode()
        {
            return dar.GetPeriodCode();
        }

        /// <summary>
        /// 获取名称(用于绑定下拉框)
        /// </summary>
        /// <returns></returns>
        public DataSet GetDepositTypeID()
        {
            return dar.GetDepositTypeID();
        }

        /// <summary>
        /// 获取手工录入的列表（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<ManualEntryInfo> SelManualEntryInfo(int pagesize, int startindex, string strquery)
        {
            IList<ManualEntryInfo> manlist = new List<ManualEntryInfo>();
            ManualEntryInfo maninfo;
            DataSet ds = dar.SelManualEntryInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                maninfo = new ManualEntryInfo()
                {
                    ID = Convert.ToInt32(item["ID"]),
                    RDATE = Convert.ToDateTime(item["RDATETIME"]),
                    NODENAME = item["NODENAME"].ToString(),
                    PERIOD_NAME = item["PERIOD_NAME"].ToString(),
                    DEPOSITNAME = item["DEPOSITNAME"].ToString(),
                    Price = Convert.ToDecimal(item["Price"]),
                    Count = Convert.ToInt32(item["Count"]),
                    ConMoney = Convert.ToDecimal(item["ConMoney"]),
                    OperatorID = item["OperatorID"].ToString()
                };
                manlist.Add(maninfo);
            }
            return manlist;
        }
        /// <summary>
        /// 保存（新增）
        /// </summary>
        /// <param name="man"></param>
        /// <returns></returns>
        public int SaveManualEntryAdd(ManualEntryInfo man)
        {
            object[] obj = new object[] { man.RDATE, man.MacID, man.PeriodCode, man.DepositTypeID, man.Count, man.OperatorID, man.MenuAll };
            return dar.SaveManualEntryAdd(obj);
        }

        /// <summary>
        /// 根据编号获取一条手工录入信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ManualEntryInfo GetManualEntryInfoOne(string id)
        {
            dar = new DataAccessManualEntry();
            DataSet ds = dar.GetManualEntryInfoOne(id);
            ManualEntryInfo info = new ManualEntryInfo();
            info.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
            info.RDATE = Convert.ToDateTime(ds.Tables[0].Rows[0]["RDATE"]);
            info.NODENAME = ds.Tables[0].Rows[0]["NODENAME"].ToString();
            info.PERIOD_NAME = ds.Tables[0].Rows[0]["PERIOD_NAME"].ToString();
            info.DEPOSITNAME = ds.Tables[0].Rows[0]["DEPOSITNAME"].ToString();
            info.Count = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]);

            //info.MacID = Convert.ToInt32(ds.Tables[0].Rows[0]["MACNO"]);
            //info.PeriodCode = Convert.ToInt32(ds.Tables[0].Rows[0]["Period_Code"]);
            //info.DepositTypeID = Convert.ToInt32(ds.Tables[0].Rows[0]["DEALMARK"]);
            //info.Price = Convert.ToDecimal(ds.Tables[0].Rows[0]["Price"]);
            //info.Count = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]);
            //info.ConMoney = Convert.ToDecimal(ds.Tables[0].Rows[0]["CONMONEY"]);
            return info;
        }

        /// <summary>
        /// 根据RecordId编号获取RecordDetail表中的菜单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataSet GetCon_Menus(string id)
        {
            dar = new DataAccessManualEntry();
            DataSet ds = dar.GetCon_Menus(id);
            return ds;
        }

        /// <summary>
        /// 保存(修改界面下)
        /// </summary>
        /// <param name="man"></param>
        /// <returns></returns>
        public int SaveManualEntryEdit(ManualEntryInfo man)
        {
            object[] obj = new object[] { man.ID, man.MenuAll, man.Count };
            return dar.SaveManualEntryEdit(obj);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteManualEntry(string id)
        {
            return dar.DeleteManualEntry(id);
        }
    }
}
